﻿using System;
using System.Collections.Generic;
using System.Text;
using GroupChat2013.Entity;
using GroupChat2013.Service;
using System.IO;
using GroupChat2013.Common;
using GroupChat2013.Logic;

namespace GroupChat2013.Logic
{
    /// <summary>
    /// 群配置按钮解析类
    /// </summary>
    public class GroupButtonConfigParse : BaseConfigParse
    {
        /// <summary>
        /// 解析
        /// </summary>
        /// <returns>按钮信息数组</returns>
        public override List<ButtonConfigInfo> Parse()
        {
            Dictionary<string, ButtonConfigInfo> dic = ServiceUrlProxy.GetInstance().GetGroupAppConfig();

            List<ButtonConfigInfo> configList = new List<ButtonConfigInfo>();
            if (dic != null && dic.Values.Count > 0)
            {

                foreach (var value in dic.Values)
                {
                    DownLoadButtonImage(value);

                    if (string.IsNullOrEmpty(value.addr))
                    {
                        string slipt = value.link.IndexOf("/") == 0 ? "" : "/";
                        value.link = string.Format("http://{0}{1}", ServiceUrlProxy.GetInstance().m_BaseUrl, slipt + value.link);
                    }
                    else
                        value.link = string.Format(value.addr, value.link);

                    configList.Add(value);
                }
            }

            configList.Sort((x, y) =>
            {
                return x.Index - y.Index;
            });

            return configList;
        }
    }
}
